import Taro, { Component } from '@tarojs/taro'
import { Image, Text, View } from '@tarojs/components'
import './index.scss'
import classNames from 'classnames'
import { toGoodsPage } from "@/utils/page_router"
import { formatAmount, getThumbnailConfig, headImg } from "@/utils/utils"
import {FyImg, NeedScore, SalePrice} from "@/components/index";
import {getBrand, goodsScore} from "@/utils/storage";

const prefixCls = 'cart-goods'
export default class Index extends Component {
  props: any

  static options = {
    addGlobalClass: true
  }

  //  点击事件
  onClick() {
    const { info, isJump, onClick } = this.props
    if (onClick) {
      return onClick()
    }
    isJump && toGoodsPage(info)
  }

  render() {
    const { info, className } = this.props
    return info && (<View className={classNames(prefixCls, className)} onClick={this.onClick.bind(this)}>
      <FyImg src={getThumbnailConfig(headImg(info.images), 320, 320)} className={`${prefixCls}__img`} lazyLoad/>
      <View  className={`${prefixCls}__box d-f f-d-c j-c-b`}>
        <View className={`${prefixCls}__head`}>
          <View className={`${prefixCls}__name t-o-e-2`}>{info.name}</View>
          {info.specSnap && <View className={`${prefixCls}__attr-name t-o-e`}>{info.specSnap}</View>}
        </View>
        <View className={`${prefixCls}__foot d-f a-i-b j-c-b`}>
          <View className='d-f a-i-b'>
            {/*<View className='needScore'>{info.needScore}{getBrand()}</View>*/}
            {goodsScore(info.needScore) &&<NeedScore goods={info} priceSize={44} className='m-r-10'/>}
            <SalePrice goods={info} priceSize={32} isNumber/>
            {/*<s className='originPrice'>{Number(info.originPrice)}元</s>*/}
          </View>
          {/*<View className={`${prefixCls}__price bnn-number`}>*/}
          {/*  <Text className={`${prefixCls}__unit`}>￥</Text>{formatAmount(info.salePrice)}*/}
          {/*</View>*/}
          <View  className={`${prefixCls}__num`}>x{info.number}</View>
        </View>
      </View>
    </View>)
  }
}
